package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.supplier3.SupplierEntity3;
import com.swgk.core.dialog.BaseBottomDialog;
import com.swgk.core.dialog.DialogViewHolder;

public class MapInfoDialog3 extends BaseBottomDialog {

    private SupplierEntity3 supplierEntity3;
    private TextView titleView;
    private TextView distanceView;
    private TextView contentView;
    private TextView shopView;
    private TextView timeView;
    private TextView authView;
    private ImageView imageView;
    private DialogClickCallBack dialogClickCallBack;

    public MapInfoDialog3(Context context, DialogCallBack dialogCallBack) {
        super(context, dialogCallBack);
    }

    public MapInfoDialog3(Context context, int theme, DialogCallBack dialogCallBack) {
        super(context, theme, dialogCallBack);
    }

    @Override
    protected int dialogLayout() {
        return R.layout.map_info_dialog;
    }

    @Override
    protected void initView(DialogViewHolder holder,Bundle savedInstanceState) {
        imageView = holder.getDialog().findViewById(R.id.img_view);
        titleView = holder.getDialog().findViewById(R.id.title_view);
        distanceView = holder.getDialog().findViewById(R.id.distance_view);
        contentView = holder.getDialog().findViewById(R.id.content_view);
        timeView = holder.getDialog().findViewById(R.id.time_view);
        authView = holder.getDialog().findViewById(R.id.auth_view);
        shopView = holder.getDialog().findViewById(R.id.shop_view);
        shopView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialogClickCallBack == null) {
                    return;
                }
                if (supplierEntity3 == null) {
                    return;
                }
                dialogClickCallBack.onClickShop(supplierEntity3.getId());
            }
        });
    }

    public SupplierEntity3 getData() {
        return supplierEntity3;
    }

    public MapInfoDialog3 setData(SupplierEntity3 supplierEntity3) {
        this.supplierEntity3 = supplierEntity3;
        titleView.setText(supplierEntity3.getTitle());
        distanceView.setText(supplierEntity3.getDistance());
        contentView.setText("主营：" + supplierEntity3.getContent());
        timeView.setText(supplierEntity3.getSettlingTime());
        authView.setText(supplierEntity3.getIsAuth());

        RequestOptions options = new RequestOptions()
                .dontAnimate()
                .placeholder(R.drawable.null_img_list)
                .error(R.drawable.null_img_list)
                .centerCrop();
        Glide.with(context)
                .load(supplierEntity3.getImgUrl())
                .apply(options)
                .into(imageView);

        return this;
    }

    public interface DialogClickCallBack {
        void onClickShop(String shopId);
    }

    public MapInfoDialog3 setDialogClickCallBack(DialogClickCallBack dialogClickCallBack) {
        this.dialogClickCallBack = dialogClickCallBack;
        return this;
    }
}
